package elcs.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import elcs.member.model.MemberService;
import elcs.member.model.MemberVO;

@Controller
public class MemberController {
	@Resource(name="memberServiceImpl")
	private MemberService memberService;
	
	//이정현
	@RequestMapping("/member/mygpage.do")
	public String mypageView(){
		System.out.println("mypageView");
		
		return "mypage.member";
	}
	
	
	//최성찬
	@ResponseBody
	@RequestMapping("/member/login.do")
	public boolean loginAjax(HttpSession session,MemberVO mvo)
	{
		System.out.println("login");
		boolean flag=true;
		
		mvo=memberService.login(session,mvo);
		if(mvo==null)
		{
			flag=false;
		}
		System.out.println(mvo);
		System.out.println(flag);
		
		
		return flag;
	}
	@RequestMapping("/member/logout.do")
	public String logout(HttpSession session)
	{
		System.out.println("logout");
		memberService.logout(session);
		
		return "redirect:../main.do";
	}
	
	@RequestMapping("/member/register.do")
	public String register(MemberVO mvo)
	{
		System.out.println("register");
		memberService.register(mvo);
		
		return "redirect:../main.do";
	}
	@ResponseBody
	@RequestMapping("/member/checkMemberById.do")
	public boolean checkMemberByIdAjax(String id)
	{
		System.out.println("checkMemberByIdAjax");
		return memberService.checkMemberById(id);
	}
	
	@ResponseBody
	@RequestMapping("/member/checkMemberByNick.do")
	public boolean checkMemberByNickAjax(String nick)
	{
		System.out.println("checkMemberByNickAjax");
		return memberService.checkMemberByNick(nick);
	}
	
	
	
	

	
}
